import java.util.*;

import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;

public class SimpleSendMessage {

  public static void main(String[] args) {
    String host = "server.yourhost.com";
    String to = "kingsummon@gmail.com";
    String from = "kingsummon@gmail.com";
    String subject = "an email";
    String messageText = "From Jsp.";
    boolean sessionDebug = false;

    Properties props = System.getProperties();
    props.put("mail.smtp.host", "smtp.gmail.com" );
    props.put("mail.smtp.port", "465" );

  //  props.put("mail.transport.protocol", "smtp");

    Session session = Session.getDefaultInstance(props, null);

    session.setDebug(sessionDebug);

    try {
      Message msg = new MimeMessage(session);
      msg.setFrom(new InternetAddress(from));
      InternetAddress[] address = {new InternetAddress(to)};
      msg.setRecipients(Message.RecipientType.TO, address);
      msg.setSubject(subject);
      msg.setSentDate(new Date());
      msg.setText(messageText);
      Transport.send(msg);
    }catch (MessagingException mex) {
      mex.printStackTrace();
    }
  }
}
